//
//  BkJuBaoViewController.m
//  TuDianEducation
//
//  Created by lixinkeji on 2021/2/1.
//  Copyright © 2021 zhangbenchao. All rights reserved.
//

#import "BkJuBaoViewController.h"
#import "PopoverViewController.h"
@interface BkJuBaoViewController ()<UIPopoverPresentationControllerDelegate,UITextViewDelegate>
@property (nonatomic, strong) UIView *bacView;
@property (nonatomic,strong) UILabel *messageLabel;

@property (nonatomic, strong) UIButton *commitBtn;
@property (nonatomic,strong) UIButton *cancellBtn;
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UILabel *placeHolderLabel;


@end

@implementation BkJuBaoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = YES;
    self.view.backgroundColor = kBacColor;
   
    [self.view addSubview:self.bacView];
    [self.bacView addSubview:self.messageLabel];
    [self.bacView addSubview:self.textView];
    [self.bacView addSubview:self.placeHolderLabel];
    self.bacView.height = self.textView.bottom + TSScaleW(70);
    [self.bacView addSubview:self.cancellBtn];
    [self.bacView addSubview:self.commitBtn];
    
    
}

-(UIView *)bacView{
    if (!_bacView) {
        _bacView = [[UIView alloc]initWithFrame:CGRectMake(TSScaleW(34), 0, TSScaleW(307), TSScaleW(170))];
        _bacView.centerY = TSScreenHeight/3.f;
        [_bacView setCornerRadius:TSScaleW(10)];
        _bacView.backgroundColor = kWhiteColor;
    }
    return _bacView;
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    //self.navigationController.navigationBarHidden = YES;
}

-(UILabel *)messageLabel{
    if (!_messageLabel) {
        _messageLabel = [TSWLTools allocLabel:@"举报用户" font:systemFont(TSScaleW(16)) textColor:kMainTxtColor frame:CGRectMake(TSScaleW(0), TSScaleW(20), _bacView.width, TSScaleW(30)) textAlignment:(NSTextAlignmentCenter)];
        
    }
    return _messageLabel;
}

-(UITextView *)textView
{
    if (!_textView) {
        _textView = [[UITextView alloc]initWithFrame:CGRectMake(TSScaleW(20), TSScaleW(10) + self.messageLabel.bottom, _bacView.width - TSScaleW(40), TSScaleW(70))];
        _textView.delegate = self;
        _textView.font = kFont(15);
        _textView.backgroundColor = kMainBgColor;
    }
    return _textView;
}
-(UILabel *)placeHolderLabel{
    if (!_placeHolderLabel) {
        _placeHolderLabel = [TSWLTools allocLabel:@"请输入您的举报内容" font:systemFont(14) textColor:kGrayTxtColor frame:CGRectMake(_textView.left, _textView.top + TSScaleW(5), _textView.width - TSScaleW(20), TSScaleW(14)) textAlignment:(NSTextAlignmentLeft)];
    }
    return _placeHolderLabel;
}
#pragma mark ------textViewDelegate

-(void)textViewDidBeginEditing:(UITextView *)textView
{
    self.placeHolderLabel.hidden = YES;
}


- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    NSString *contentString = [textView.text stringByReplacingCharactersInRange:range withString:text];
    
    if (contentString.length == 0) {
        self.placeHolderLabel.hidden = NO;
    }else{
        self.placeHolderLabel.hidden = YES;
    }
   
    
    return YES;
}
-(UIButton *)commitBtn{
    if (!_commitBtn) {
       _commitBtn = [TSWLTools allocButtonTitle:@"确认" font:systemBoldFont(14) textColor:kGreenColor image:nil frame:CGRectMake(_bacView.width/2.f, 0, TSScaleW(120), TSScaleW(50)) sel:@selector(commitAction:) taget:self];
        _commitBtn.bottom = _bacView.height;
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _cancellBtn.width, 0.5)];
        line.backgroundColor = kMainLineColor;
        [_commitBtn addSubview:line];
        UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, _cancellBtn.width, 0.5)];
        line2.backgroundColor = kMainLineColor;
        [_commitBtn addSubview:line2];
    }
    return _commitBtn;
}
-(UIButton *)cancellBtn{
    if (!_cancellBtn) {
        _cancellBtn = [TSWLTools allocButtonTitle:@"取消" font:systemBoldFont(14) textColor:kMainTxtColor image:nil frame:CGRectMake(0, 0, TSScaleW(120), TSScaleW(50)) sel:@selector(cancellBtnAction:) taget:self];
        _cancellBtn.bottom = _bacView.height;
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 0, .5f, _cancellBtn.height)];
        line.backgroundColor = kMainLineColor;
        [_cancellBtn addSubview:line];
        
    }
    return _cancellBtn;
}

-(void)commitAction:(UIButton *)sender
{
    NSString *string = _textView.text;
    if (!string.length) {
        [MBProgressHUD showError:@"请输入您的举报内容"];
        return;
    }
    WS(weakSelf);
    [self dismissViewControllerAnimated:YES completion:^{
        !weakSelf.callBackBlcok?:weakSelf.callBackBlcok(string);
    }];
    
}
-(void)cancellBtnAction:(UIButton *)sender
{
    [self dismissViewControllerAnimated:YES completion:^{
            
    }];
}
-(void)dismissAction{
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
